package com.kayak.tg.client.config;

import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import com.baomidou.mybatisplus.extension.spring.MybatisMapperRefresh;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternResolver;

/**
 * MybatisPlus配置
 * @author xiamh
 * @date 2017年9月11日 下午7:19:10
 */
@Configuration
//@MapperScan(basePackages = {"com.*.mapper*","com.*.*.mapper*"})   //mapper类映射路径
public class MybatisPlusConfig {

    /**
     * mybatis-plus 分页拦截器
     */
    @Bean
    public PaginationInterceptor paginationInterceptor() {
        PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
//		paginationInterceptor.setLocalPage(true);
        return paginationInterceptor;
    }

    /**
     * xml热加载插件
     * @return
     */
    @Bean
    public MybatisMapperRefresh mybatisMapperRefresh(SqlSessionFactory sqlSessionFactory) throws Exception {
        ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
        Resource[] resources = resolver.getResources("classpath*:mapper/**/*mapper.xml");
        MybatisMapperRefresh mybatisMapperRefresh = new MybatisMapperRefresh(resources, sqlSessionFactory, 10, 5, true);
        return mybatisMapperRefresh;
    }

}
